//
//  ExamSignUpViewController.m
//  CommunityNannyO2O
//
//  Created by 90 on 15/7/21.
//  Copyright (c) 2015年 Apple. All rights reserved.
//

#import "ExamSignUpViewController.h"
#import "AppConfig.h"
#import "QXNetWorkTool.h"
#import "APIAdress.h"
#import "MBProgressHUD+YC.h"
#import "MJExtension.h"
#import "AccountTool.h"
#import "ExamSignUpTableViewCellFirst.h"
#import "ExamSignUpTableViewCellSecond.h"
#import "ExamSignUpTableViewCellThird.h"
#import "ExamSignUpTableViewCellFouth.h"
#import "ExamSignUpTableViewCellFirth.h"
#import "ExamSignUpTableViewCellSix.h"
#import "SelectExamLevelView.h"
#import "ExamGuideViewController.h"
#import "ExamCourseViewController.h"

@interface ExamSignUpViewController()<QXNetWorkToolDelegate,
        UITableViewDataSource,UITableViewDelegate,
        LevelDeletage,SelectExamLevelDeletage,
        CourseDeletage,SelectExamCourseViewDeletage,
        ExamGuideTableViewCellDeletage>
{

}

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSMutableArray *data;
@property (nonatomic, strong) NSDate *selectedDate;
@property (nonatomic, strong) NSString *examLevel;
@property (nonatomic, strong) NSString *examCourse;
@end


@implementation ExamSignUpViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.tableView.dataSource = self;
    
    self.tableView.delegate = self;
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.data = [NSMutableArray arrayWithObjects:@"等级1", @"等级2", @"等级3", @"等级4",@"等级5",nil];
    
    self.examLevel = @"等级1";
    self.examCourse = @"电吉他";
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        return 141;
    }
    else if (indexPath.row == 1)
    {
        return 88;
    }
    else if (indexPath.row == 2)
    {
        return 97;
    }
    else if (indexPath.row == 3)
    {
        return 68;
    }
    else if (indexPath.row == 4)
    {
        return 66;
    }
    else if (indexPath.row == 5)
    {
        return 79;
    }
    return 50;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0)
    {
        ExamSignUpTableViewCellFirst *cell = [ExamSignUpTableViewCellFirst cellWithTableView:tableView];
        
        return cell;
    }
    else if (indexPath.row == 1)
    {
        ExamSignUpTableViewCellSecond *cell = [ExamSignUpTableViewCellSecond cellWithTableView:tableView];
        
        return cell;
    }
    else if (indexPath.row == 2)
    {
        ExamSignUpTableViewCellThird *cell = [ExamSignUpTableViewCellThird cellWithTableView:tableView];
        cell.courseDeletage = self;
        cell.lession.text = self.examCourse;
        return cell;
    }
    else if (indexPath.row == 3)
    {
        ExamSignUpTableViewCellFouth *cell = [ExamSignUpTableViewCellFouth cellWithTableView:tableView];
        cell.levelDelegate = self;
        cell.level.text = self.examLevel;
        return cell;
    }
    else if (indexPath.row == 4)
    {
        ExamSignUpTableViewCellFirth *cell = [ExamSignUpTableViewCellFirth cellWithTableView:tableView];
        cell.examGuideDelegate = self;
        return cell;
    }
    else if (indexPath.row == 5)
    {
        ExamSignUpTableViewCellSix *cell = [ExamSignUpTableViewCellSix cellWithTableView:tableView];
        return cell;
    }
    
    UITableViewCell *cell = [[UITableViewCell alloc] init];
    
    return cell;
}


-(void)configNavigationItem
{
    self.navigationItem.title = @"报名";
    [self.navigationController.navigationBar setTranslucent:NO];
    
    [self.navigationController.navigationBar
     setBackgroundImage:[UIImage imageNamed:@"bg_navigation_bar"]
     forBarMetrics:UIBarMetricsDefault];
    
    //status bar的字体为白色
    //导航栏的背景色是黑色
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0],UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:18.0],NSFontAttributeName,nil]];
    
    [self configNavigationBackAction:^{
        
        [self.navigationController popViewControllerAnimated:YES];
    }];
}

-(void)useMethodToFindBlackLineAndHind
{
    UIImageView* blackLineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
    
    blackLineImageView.hidden = YES;
}

-(void)didSelectLevel
{
    SelectExamLevelView *obj = [SelectExamLevelView create];
    obj.view.backgroundColor = [UIColor clearColor];
    obj.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    obj.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    obj.definesPresentationContext = YES;
    obj.selectExamlevelDelegate = self;
    
    [obj setLevelData:self.data];
    [self presentViewController:obj animated:YES completion:nil];
}

-(void)setLevel:(NSString *)str
{
    self.examLevel = str;
    
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:3 inSection:0];
    NSArray *indexArray = [NSArray arrayWithObject:indexPath];
    
    [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationAutomatic];
}

-(void)didSelectCourse
{
    ExamCourseViewController *obj = [ExamCourseViewController create];
    obj.selectExamCourseDelegate = self;
    [self.navigationController pushViewController:obj animated:YES];
}

-(void)setSelectExamCourse:(NSString *)str
{
    self.examCourse = str;
    
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2
                                                inSection:0];
    NSArray *indexArray = [NSArray arrayWithObject:indexPath];
    
    [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationAutomatic];
}

-(void)showExamGuide
{
    ExamGuideViewController *obj = [ExamGuideViewController create];
    
    [self.navigationController pushViewController:obj animated:YES];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self configNavigationItem];

    [self useMethodToFindBlackLineAndHind];
}

-(void)viewWillDisappear:(BOOL)animated
{

}


@end









